from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5 import QtGui

import sys

class MyCombo(QtWidgets.QComboBox):
    def __init__(self, title, parent=None):
        super(MyCombo, self).__init__(parent)

        self.setAcceptDrops(True)

    def dragEnterEvent(self, e):
        if e.mimeData().hasText():
            e.accept()
        else:
            e.ignore()

    def dropEvent(self, e):
        self.addItem(e.mimeData().text())

class QDragTest(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(QDragTest, self).__init__(parent)

        self.setWindowTitle("QDragTest例子")

        self.initUi()

    def initUi(self):
        lo = QtWidgets.QFormLayout()
        lo.addRow(QtWidgets.QLabel("请把左边的文本拖拽到右边的下拉菜单中"))

        edit = QtWidgets.QLineEdit()
        edit.setDragEnabled(True)

        com = MyCombo("Button", self)
        lo.addRow(edit, com)

        self.setLayout(lo)




if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    QtWidgets.QApplication.setStyle("Fusion")
    win = QDragTest()
    win.show()
    sys.exit(app.exec_())